package com.it.springbootmybatis.service.impl;

import com.it.springbootmybatis.dao.CompanyDao;
import com.it.springbootmybatis.domain.Company;
import com.it.springbootmybatis.query.CompanyQuery;
import com.it.springbootmybatis.service.ICompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @projectName: springboot-practice
 * @package: com.it.springbootmybatis.service.impl
 * @className: CompanyServiceImpl
 * @author: Navid
 * @description: TODO
 * @date: 2021/10/23 13:27
 * @version: 1.0
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class CompanyServiceImpl implements ICompanyService {

    @Autowired
    CompanyDao dao;

    /**
     * 查询所有
     *
     * @return: 公司列表数据
     */
    @Override
    public List<Company> findAll() {
        return dao.findAll();
    }

    @Override
    public void insert(Company company) {
        dao.insert(company);
    }

    @Override
    public void delete(int id) {
        dao.delete(id);
    }

    @Override
    public List<Company> queryPaged(CompanyQuery companyQuery) {
        return dao.queryPaged(companyQuery);
    }



    /**
     * 查询所有
     * 排除事务readOnly = true  Propagation.SUPPORTS:如果该方法有事务才使用事务,没有事务就不使事务
     *
     * @return: 公司列表数据
     */
    @Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
    public List<Company> findAll3() {
        return dao.findAll();
    }
}
